def write_text():
    f = open('test.txt','w', encoding='utf-8')
    s = '文件读写测试'
    f.write(s)
    f.close() #每次io过程都要记得最后释放io流资源

def read_text():
    fp = open('test.txt','r', encoding='utf-8')
    print(fp.read((4)))
    fp.close()

def read_line():
    fp = open('test.txt','r', encoding='utf-8')
    while True:
        line = fp.readline()
        if line == '': #读到最后一行停止while
            break
        print(line)
    fp.close()

#write_text
read_text()
read_line()